package dshop.model.company;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;

import appbase.jfinal.ext.BaseModel;

public class CompanyAuthenticationImage extends BaseModel<CompanyAuthenticationImage>{
	
	private static final long serialVersionUID = -6967680902549117464L;
	
	public static final CompanyAuthenticationImage dao = new CompanyAuthenticationImage();

	
	public static void saveImageList(int accountId, String[] imageUrlArr) 
	{
		if (imageUrlArr == null || imageUrlArr.length <= 0)
		{
			return;
		}
		
		List<CompanyAuthenticationImage> imageList = new ArrayList<>();
		for (int i = 0; i < imageUrlArr.length; i++) 
		{
			if (imageUrlArr[i] == null || imageUrlArr[i].isEmpty())
			{
				continue;
			}
			
			CompanyAuthenticationImage image = new CompanyAuthenticationImage();
			image.set("account_id", accountId)
				 .set("img", imageUrlArr[i]);
			
			imageList.add(image);
		}
		
		dao.saveList(imageList);
	}


	public static void setImageListTo(List<Record> list, String accountIdColumn, String newImageListName) 
	{
		dao.mergeModelsTo(list, accountIdColumn, "account_id, img", "account_id", newImageListName);
	}


	public static void deleteBy(int accountId) 
	{
		dao.deleteByColumns("account_id", accountId);
	}

}
